package cn.gok.day4;

import java.util.Objects;
import java.util.Scanner;

/**
 * @ClassName Student
 * @Description TODO
 * @Author HP
 * @Date 9:38 2022/7/7
 * @Version 1.0
 **/
public class Student implements Cloneable{
    private String sname;
    private String sid;
    private String sex;
    private int age;

    public Student() {
    }

    public Student(String sname, String sid, String sex, int age) {
        this.sname = sname;
        this.sid = sid;
        this.sex = sex;
        this.age = age;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public String getSid() {
        return sid;
    }

    public void setSid(String sid) {
        this.sid = sid;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "sname='" + sname + '\'' +
                ", sid='" + sid + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }

//    重写equals以及hasCode方法，实现凭借两个参数判断是否为同一个对象
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Student student = (Student) o;
        return  Objects.equals(sname, student.sname) && Objects.equals(sid, student.sid) ;
    }

    @Override
    public int hashCode() {
        return Objects.hash(sname, sid);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static void main(String[] args) throws CloneNotSupportedException {
//        Student student1=new Student("oscar","194033531","男",22);
//        Student student2=new Student("oscar","194033531","女",19);
//        System.out.println(student2.equals(student1));
//浅拷贝和深拷贝的区别 //浅拷贝连hascode都相同，所以一个改变，另外一个也会改变，深拷贝是另外的对象，一个改变另外一个不会改变
        Student student3=new Student("oscar","194033531","男",22);
        Student student4=student3;

//        System.out.println(student4.hashCode()+" "+student3.hashCode());
        Student student5=(Student) student3.clone();
        student3.setSname("zhangsan");
        System.out.println(student5.hashCode()+" "+student3.hashCode());

    }
}
